class A implements Runnable
{
    public  int tickets = 10000;
   
    public void run()
    {
        while(true)
        {
            synchronized(this)
            {
                if(tickets > 0)
                {
                    System.out.printf("%s正在卖出第%d张票\n",Thread.currentThread().getName(),tickets--);
                }
                else 
                {
                    break;
                }
            }
        }
    }
}
public class TestTickets_1
{
    public static void main(String[] args)
    {
        A aa = new A();

        Thread t1 = new Thread(aa);
        t1.start();
        Thread t2 = new Thread(aa);
        t2.start();
    }
}
/*
推荐使用继承接口的方法来实现
因为本方法不需要 new 出多个对象
*/